﻿
@using TagHelperSample.Web.Models
@model User

@{
    Html.Html5DateRenderingMode = Html5DateRenderingMode.Rfc3339;
}

<h2>Create</h2>

@* anti-forgery is on by default *@
@* <form/> tag helper will special-case only elements with an "asp-action" or "asp-anti-forgery" attribute. *@
<form asp-anti-forgery="false" asp-action="Create">
    <div class="form-horizontal">
        @* validation summary tag helper will target just <div/> elements and append the list of errors *@
        @* - i.e. this helper, like <select/> helper appends content. *@
        @* helper does nothing if model is valid and (client-side validation is disabled or
           asp-validation-summary="ValidationSummary.ModelOnly") *@
        @* don't need a bound attribute to match Html.ValidationSummary()'s headerTag parameter; users wrap message as they wish *@
        @* initially at least, will not remove the <div/> if list isn't generated *@
        @* - should helper remove the <div/> if list isn't generated? *@
        @* - (Html.ValidationSummary returns empty string despite non-empty message parameter) *@
        @* Acceptable values are: "None", "ModelOnly" and "All" *@
        <div asp-validation-summary="ValidationSummary.All" style="color:blue" id="validation_day" class="form-group">
            <span style="color:red">This is my message</span>
        </div>

        @* element will have correct name and id attributes for Id property. unusual part is the constant value. *@
        @* - the helper will _not_ override the user-specified "value" attribute *@
        <input type="hidden" asp-for="Id" value="0" />

        <div class="form-group">
            @* no special-case for the "asp-for" attribute; now distinct from HTML "for" attribute. *@
            <label asp-for="Name" class="control-label col-md-2" style="color:blue"></label>
            <div class="col-md-10">
                <input type="text" asp-for="Name" style="color:blue" />
                <span asp-validation-for="Name" style="color:blue"></span>
            </div>
        </div>
        <div class="form-group">
            <label asp-for="DateOfBirth" class="control-label col-md-2"></label>
            <div class="col-md-10">
                @* will automatically infer type="date" (reused HTML attribute) and asp-format="{0:yyyy-MM-dd}" (optional bound attribute) *@
                <input asp-for="DateOfBirth" />
                <span asp-validation-for="DateOfBirth">When were you born?</span>
            </div>
        </div>
        <div class="form-group">
            <label asp-for="YearsEmployeed" class="control-label col-md-2"></label>
            <div class="col-md-10">
                @* <select/> items render after static options *@
                @{ var @object = "multiple"; }
                <select asp-for="@(Model.YearsEmployeed)" asp-items="@((IEnumerable<SelectListItem>)ViewBag.Items)" size="2" class="form-control" multiple="@(@object)">
                    @* Static use of "selected" attribute may cause HTML errors if in a single-selection <select/> *@
                    @* - @NTaylorMullen thinks <option/> tag helper could tell <select/> helper not to select anything from "items" *@
                    @* - wouldn't help if user selected one static <option/> and expression indicated another, especially one earlier in the <select/> *@
                    @* - may need a "default" bound parameter on the <select/> to avoid these cases and maintain "don't override" *@
                    <option value="" selected="selected">Why didn't you select anything?</option>
                    <optgroup label="Newby">
                        <option value="0">Less than 1</option>
                        <option value="1">1</option>
                    </optgroup>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                </select>

                @* targets only <span/> in Beta; does not support equivalent of Html.ValidationMessageFor()'s tag parameter *@
                @* - may eventually either support additional tags e.g. <p/> and <div/> or all tags /> *@
                <span asp-validation-for="YearsEmployeed"></span>
            </div>
        </div>
        <div class="form-group">
            <label asp-for="Blurb" class="control-label col-md-2"></label>
            <div class="col-md-10">
                <textarea rows="4" asp-for="Blurb"></textarea>
                <span asp-validation-for="Blurb"></span>
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                @* this <input/> lacks a "asp-for" attribute and will not be changed by the <input/> tag helper *@
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
</form>

<div>
    <a asp-action="Index">Back to list</a>
</div>
